<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>abstractdialogplugin_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_editor_plugins_abstractdialogplugin_test.js.html">abstractdialogplugin_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.editor.plugins.AbstractDialogPluginTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.editor.plugins.AbstractDialogPluginTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.dom.SavedRange&#39;);
<a name="line19"></a>goog.require(&#39;goog.editor.Field&#39;);
<a name="line20"></a>goog.require(&#39;goog.editor.plugins.AbstractDialogPlugin&#39;);
<a name="line21"></a>goog.require(&#39;goog.events.Event&#39;);
<a name="line22"></a>goog.require(&#39;goog.events.EventHandler&#39;);
<a name="line23"></a>goog.require(&#39;goog.functions&#39;);
<a name="line24"></a>goog.require(&#39;goog.testing.MockClock&#39;);
<a name="line25"></a>goog.require(&#39;goog.testing.MockControl&#39;);
<a name="line26"></a>goog.require(&#39;goog.testing.PropertyReplacer&#39;);
<a name="line27"></a>goog.require(&#39;goog.testing.editor.FieldMock&#39;);
<a name="line28"></a>goog.require(&#39;goog.testing.editor.TestHelper&#39;);
<a name="line29"></a>goog.require(&#39;goog.testing.events&#39;);
<a name="line30"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line31"></a>goog.require(&#39;goog.testing.mockmatchers.ArgumentMatcher&#39;);
<a name="line32"></a>goog.require(&#39;goog.ui.editor.AbstractDialog&#39;);
<a name="line33"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line34"></a>
<a name="line35"></a>var plugin;
<a name="line36"></a>var mockCtrl;
<a name="line37"></a>var mockField;
<a name="line38"></a>var mockSavedRange;
<a name="line39"></a>var mockOpenedHandler;
<a name="line40"></a>var mockClosedHandler;
<a name="line41"></a>
<a name="line42"></a>var COMMAND = &#39;myCommand&#39;;
<a name="line43"></a>var stubs = new goog.testing.PropertyReplacer();
<a name="line44"></a>
<a name="line45"></a>var mockClock;
<a name="line46"></a>var fieldObj;
<a name="line47"></a>var fieldElem;
<a name="line48"></a>var mockHandler;
<a name="line49"></a>
<a name="line50"></a>function setUp() {
<a name="line51"></a>  mockCtrl = new goog.testing.MockControl();
<a name="line52"></a>  mockOpenedHandler = mockCtrl.createLooseMock(goog.events.EventHandler);
<a name="line53"></a>  mockClosedHandler = mockCtrl.createLooseMock(goog.events.EventHandler);
<a name="line54"></a>
<a name="line55"></a>  mockField = new goog.testing.editor.FieldMock(undefined, undefined, {});
<a name="line56"></a>  mockCtrl.addMock(mockField);
<a name="line57"></a>  mockField.focus();
<a name="line58"></a>
<a name="line59"></a>  plugin = createDialogPlugin();
<a name="line60"></a>}
<a name="line61"></a>
<a name="line62"></a>function setUpMockRange() {
<a name="line63"></a>  mockSavedRange = mockCtrl.createLooseMock(goog.dom.SavedRange);
<a name="line64"></a>  mockSavedRange.restore();
<a name="line65"></a>
<a name="line66"></a>  stubs.setPath(&#39;goog.editor.range.saveUsingNormalizedCarets&#39;,
<a name="line67"></a>      goog.functions.constant(mockSavedRange));
<a name="line68"></a>}
<a name="line69"></a>
<a name="line70"></a>function tearDown() {
<a name="line71"></a>  stubs.reset();
<a name="line72"></a>  tearDownRealEditableField();
<a name="line73"></a>  if (mockClock) {
<a name="line74"></a>    // Crucial to letting time operations work normally in the rest of tests.
<a name="line75"></a>    mockClock.dispose();
<a name="line76"></a>  }
<a name="line77"></a>  if (plugin) {
<a name="line78"></a>    mockField.$setIgnoreUnexpectedCalls(true);
<a name="line79"></a>    plugin.dispose();
<a name="line80"></a>  }
<a name="line81"></a>}
<a name="line82"></a>
<a name="line83"></a>
<a name="line84"></a>/**
<a name="line85"></a> * Creates a concrete instance of goog.ui.editor.AbstractDialog by adding
<a name="line86"></a> * a plain implementation of createDialogControl().
<a name="line87"></a> * @param {goog.dom.DomHelper} dialogDomHelper The dom helper to be used to
<a name="line88"></a> *     create the dialog.
<a name="line89"></a> * @return {goog.ui.editor.AbstractDialog} The created dialog.
<a name="line90"></a> */
<a name="line91"></a>function createDialog(domHelper) {
<a name="line92"></a>  var dialog = new goog.ui.editor.AbstractDialog(domHelper);
<a name="line93"></a>  dialog.createDialogControl = function() {
<a name="line94"></a>    return new goog.ui.editor.AbstractDialog.Builder(dialog).build();
<a name="line95"></a>  };
<a name="line96"></a>  return dialog;
<a name="line97"></a>}
<a name="line98"></a>
<a name="line99"></a>
<a name="line100"></a>/**
<a name="line101"></a> * Creates a concrete instance of the abstract class
<a name="line102"></a> * goog.editor.plugins.AbstractDialogPlugin
<a name="line103"></a> * and registers it with the mock editable field being used.
<a name="line104"></a> * @return {goog.editor.plugins.AbstractDialogPlugin} The created plugin.
<a name="line105"></a> */
<a name="line106"></a>function createDialogPlugin() {
<a name="line107"></a>  var plugin = new goog.editor.plugins.AbstractDialogPlugin(COMMAND);
<a name="line108"></a>  plugin.createDialog = createDialog;
<a name="line109"></a>  plugin.returnControlToEditableField = plugin.restoreOriginalSelection;
<a name="line110"></a>  plugin.registerFieldObject(mockField);
<a name="line111"></a>  plugin.addEventListener(
<a name="line112"></a>      goog.editor.plugins.AbstractDialogPlugin.EventType.OPENED,
<a name="line113"></a>      mockOpenedHandler);
<a name="line114"></a>  plugin.addEventListener(
<a name="line115"></a>      goog.editor.plugins.AbstractDialogPlugin.EventType.CLOSED,
<a name="line116"></a>      mockClosedHandler);
<a name="line117"></a>  return plugin;
<a name="line118"></a>}
<a name="line119"></a>
<a name="line120"></a>
<a name="line121"></a>/**
<a name="line122"></a> * Sets up the mock event handler to expect an OPENED event.
<a name="line123"></a> */
<a name="line124"></a>function expectOpened(opt_times) {
<a name="line125"></a>  mockOpenedHandler.handleEvent(new goog.testing.mockmatchers.ArgumentMatcher(
<a name="line126"></a>      function(arg) {
<a name="line127"></a>        return arg.type ==
<a name="line128"></a>               goog.editor.plugins.AbstractDialogPlugin.EventType.OPENED;
<a name="line129"></a>      }));
<a name="line130"></a>  mockField.dispatchSelectionChangeEvent();
<a name="line131"></a>  if (opt_times) {
<a name="line132"></a>    mockOpenedHandler.$times(opt_times);
<a name="line133"></a>    mockField.$times(opt_times);
<a name="line134"></a>  }
<a name="line135"></a>}
<a name="line136"></a>
<a name="line137"></a>
<a name="line138"></a>/**
<a name="line139"></a> * Sets up the mock event handler to expect a CLOSED event.
<a name="line140"></a> */
<a name="line141"></a>function expectClosed(opt_times) {
<a name="line142"></a>  mockClosedHandler.handleEvent(new goog.testing.mockmatchers.ArgumentMatcher(
<a name="line143"></a>      function(arg) {
<a name="line144"></a>        return arg.type ==
<a name="line145"></a>               goog.editor.plugins.AbstractDialogPlugin.EventType.CLOSED;
<a name="line146"></a>      }));
<a name="line147"></a>  mockField.dispatchSelectionChangeEvent();
<a name="line148"></a>  if (opt_times) {
<a name="line149"></a>    mockClosedHandler.$times(opt_times);
<a name="line150"></a>    mockField.$times(opt_times);
<a name="line151"></a>  }
<a name="line152"></a>}
<a name="line153"></a>
<a name="line154"></a>
<a name="line155"></a>/**
<a name="line156"></a> * Tests the simple flow of calling execCommand (which opens the
<a name="line157"></a> * dialog) and immediately disposing of the plugin (which closes the dialog).
<a name="line158"></a> * @param {boolean=} opt_reuse Whether to set the plugin to reuse its dialog.
<a name="line159"></a> */
<a name="line160"></a>function testExecAndDispose(opt_reuse) {
<a name="line161"></a>  setUpMockRange();
<a name="line162"></a>  expectOpened();
<a name="line163"></a>  expectClosed();
<a name="line164"></a>  mockField.debounceEvent(goog.editor.Field.EventType.SELECTIONCHANGE);
<a name="line165"></a>  mockCtrl.$replayAll();
<a name="line166"></a>  if (opt_reuse) {
<a name="line167"></a>    plugin.setReuseDialog(true);
<a name="line168"></a>  }
<a name="line169"></a>  assertFalse(&#39;Dialog should not be open yet&#39;,
<a name="line170"></a>              !!plugin.getDialog() &amp;&amp; plugin.getDialog().isOpen());
<a name="line171"></a>
<a name="line172"></a>  plugin.execCommand(COMMAND);
<a name="line173"></a>  assertTrue(&#39;Dialog should be open now&#39;,
<a name="line174"></a>             !!plugin.getDialog() &amp;&amp; plugin.getDialog().isOpen());
<a name="line175"></a>
<a name="line176"></a>  var tempDialog = plugin.getDialog();
<a name="line177"></a>  plugin.dispose();
<a name="line178"></a>  assertFalse(&#39;Dialog should not still be open after disposal&#39;,
<a name="line179"></a>              tempDialog.isOpen());
<a name="line180"></a>  mockCtrl.$verifyAll();
<a name="line181"></a>}
<a name="line182"></a>
<a name="line183"></a>
<a name="line184"></a>/**
<a name="line185"></a> * Tests execCommand and dispose while reusing the dialog.
<a name="line186"></a> */
<a name="line187"></a>function testExecAndDisposeReuse() {
<a name="line188"></a>  testExecAndDispose(true);
<a name="line189"></a>}
<a name="line190"></a>
<a name="line191"></a>
<a name="line192"></a>/**
<a name="line193"></a> * Tests the flow of calling execCommand (which opens the dialog) and
<a name="line194"></a> * then hiding it (simulating that a user did somthing to cause the dialog to
<a name="line195"></a> * close).
<a name="line196"></a> * @param {boolean} reuse Whether to set the plugin to reuse its dialog.
<a name="line197"></a> */
<a name="line198"></a>function testExecAndHide(opt_reuse) {
<a name="line199"></a>  setUpMockRange();
<a name="line200"></a>  expectOpened();
<a name="line201"></a>  expectClosed();
<a name="line202"></a>  mockField.debounceEvent(goog.editor.Field.EventType.SELECTIONCHANGE);
<a name="line203"></a>  mockCtrl.$replayAll();
<a name="line204"></a>  if (opt_reuse) {
<a name="line205"></a>    plugin.setReuseDialog(true);
<a name="line206"></a>  }
<a name="line207"></a>  assertFalse(&#39;Dialog should not be open yet&#39;,
<a name="line208"></a>              !!plugin.getDialog() &amp;&amp; plugin.getDialog().isOpen());
<a name="line209"></a>
<a name="line210"></a>  plugin.execCommand(COMMAND);
<a name="line211"></a>  assertTrue(&#39;Dialog should be open now&#39;,
<a name="line212"></a>             !!plugin.getDialog() &amp;&amp; plugin.getDialog().isOpen());
<a name="line213"></a>
<a name="line214"></a>  var tempDialog = plugin.getDialog();
<a name="line215"></a>  plugin.getDialog().hide();
<a name="line216"></a>  assertFalse(&#39;Dialog should not still be open after hiding&#39;,
<a name="line217"></a>              tempDialog.isOpen());
<a name="line218"></a>  if (opt_reuse) {
<a name="line219"></a>    assertFalse(&#39;Dialog should not be disposed after hiding (will be reused)&#39;,
<a name="line220"></a>                tempDialog.isDisposed());
<a name="line221"></a>  } else {
<a name="line222"></a>    assertTrue(&#39;Dialog should be disposed after hiding&#39;,
<a name="line223"></a>               tempDialog.isDisposed());
<a name="line224"></a>  }
<a name="line225"></a>  plugin.dispose();
<a name="line226"></a>  mockCtrl.$verifyAll();
<a name="line227"></a>}
<a name="line228"></a>
<a name="line229"></a>
<a name="line230"></a>/**
<a name="line231"></a> * Tests execCommand and hide while reusing the dialog.
<a name="line232"></a> */
<a name="line233"></a>function testExecAndHideReuse() {
<a name="line234"></a>  testExecAndHide(true);
<a name="line235"></a>}
<a name="line236"></a>
<a name="line237"></a>
<a name="line238"></a>/**
<a name="line239"></a> * Tests the flow of calling execCommand (which opens a dialog) and
<a name="line240"></a> * then calling it again before the first dialog is closed. This is not
<a name="line241"></a> * something anyone should be doing since dialogs are (usually?) modal so the
<a name="line242"></a> * user can&#39;t do another execCommand before closing the first dialog. But
<a name="line243"></a> * since the API makes it possible, I thought it would be good to guard
<a name="line244"></a> * against and unit test.
<a name="line245"></a> * @param {boolean} reuse Whether to set the plugin to reuse its dialog.
<a name="line246"></a> */
<a name="line247"></a>function testExecTwice(opt_reuse) {
<a name="line248"></a>  setUpMockRange();
<a name="line249"></a>  if (opt_reuse) {
<a name="line250"></a>    expectOpened(2); // The second exec should cause a second OPENED event.
<a name="line251"></a>    // But the dialog was not closed between exec calls, so only one CLOSED is
<a name="line252"></a>    // expected.
<a name="line253"></a>    expectClosed();
<a name="line254"></a>    plugin.setReuseDialog(true);
<a name="line255"></a>    mockField.debounceEvent(goog.editor.Field.EventType.SELECTIONCHANGE);
<a name="line256"></a>  } else {
<a name="line257"></a>    expectOpened(2); // The second exec should cause a second OPENED event.
<a name="line258"></a>    // The first dialog will be disposed so there should be two CLOSED events.
<a name="line259"></a>    expectClosed(2);
<a name="line260"></a>    mockSavedRange.restore(); // Expected 2x, once already recorded in setup.
<a name="line261"></a>    mockField.focus(); // Expected 2x, once already recorded in setup.
<a name="line262"></a>    mockField.debounceEvent(goog.editor.Field.EventType.SELECTIONCHANGE);
<a name="line263"></a>    mockField.$times(2);
<a name="line264"></a>  }
<a name="line265"></a>  mockCtrl.$replayAll();
<a name="line266"></a>
<a name="line267"></a>  assertFalse(&#39;Dialog should not be open yet&#39;,
<a name="line268"></a>              !!plugin.getDialog() &amp;&amp; plugin.getDialog().isOpen());
<a name="line269"></a>
<a name="line270"></a>  plugin.execCommand(COMMAND);
<a name="line271"></a>  assertTrue(&#39;Dialog should be open now&#39;,
<a name="line272"></a>             !!plugin.getDialog() &amp;&amp; plugin.getDialog().isOpen());
<a name="line273"></a>
<a name="line274"></a>  var tempDialog = plugin.getDialog();
<a name="line275"></a>  plugin.execCommand(COMMAND);
<a name="line276"></a>  if (opt_reuse) {
<a name="line277"></a>    assertTrue(&#39;Reused dialog should still be open after second exec&#39;,
<a name="line278"></a>               tempDialog.isOpen());
<a name="line279"></a>    assertFalse(&#39;Reused dialog should not be disposed after second exec&#39;,
<a name="line280"></a>        tempDialog.isDisposed());
<a name="line281"></a>  } else {
<a name="line282"></a>    assertFalse(&#39;First dialog should not still be open after opening second&#39;,
<a name="line283"></a>                tempDialog.isOpen());
<a name="line284"></a>    assertTrue(&#39;First dialog should be disposed after opening second&#39;,
<a name="line285"></a>               tempDialog.isDisposed());
<a name="line286"></a>  }
<a name="line287"></a>  plugin.dispose();
<a name="line288"></a>  mockCtrl.$verifyAll();
<a name="line289"></a>}
<a name="line290"></a>
<a name="line291"></a>
<a name="line292"></a>/**
<a name="line293"></a> * Tests execCommand twice while reusing the dialog.
<a name="line294"></a> */
<a name="line295"></a>function testExecTwiceReuse() {
<a name="line296"></a>  // Test is failing with an out-of-memory error in IE7.
<a name="line297"></a>  if (goog.userAgent.IE &amp;&amp; !goog.userAgent.isVersionOrHigher(&#39;8&#39;)) {
<a name="line298"></a>    return;
<a name="line299"></a>  }
<a name="line300"></a>
<a name="line301"></a>  testExecTwice(true);
<a name="line302"></a>}
<a name="line303"></a>
<a name="line304"></a>
<a name="line305"></a>/**
<a name="line306"></a> * Tests that the selection is cleared when the dialog opens and is
<a name="line307"></a> * correctly restored after it closes.
<a name="line308"></a> */
<a name="line309"></a>function testRestoreSelection() {
<a name="line310"></a>  setUpRealEditableField();
<a name="line311"></a>
<a name="line312"></a>  fieldObj.setHtml(false, &#39;12345&#39;);
<a name="line313"></a>  var elem = fieldObj.getElement();
<a name="line314"></a>  var helper = new goog.testing.editor.TestHelper(elem);
<a name="line315"></a>  helper.select(&#39;12345&#39;, 1, &#39;12345&#39;, 4); // Selects &#39;234&#39;.
<a name="line316"></a>
<a name="line317"></a>  assertEquals(&#39;Incorrect text selected before dialog is opened&#39;,
<a name="line318"></a>               &#39;234&#39;,
<a name="line319"></a>               fieldObj.getRange().getText());
<a name="line320"></a>  plugin.execCommand(COMMAND);
<a name="line321"></a>  if (!goog.userAgent.IE &amp;&amp; !goog.userAgent.OPERA) {
<a name="line322"></a>    // IE returns some bogus range when field doesn&#39;t have selection.
<a name="line323"></a>    // Opera can&#39;t remove the selection from a whitebox field.
<a name="line324"></a>    assertNull(&#39;There should be no selection while dialog is open&#39;,
<a name="line325"></a>               fieldObj.getRange());
<a name="line326"></a>  }
<a name="line327"></a>  plugin.getDialog().hide();
<a name="line328"></a>  assertEquals(&#39;Incorrect text selected after dialog is closed&#39;,
<a name="line329"></a>               &#39;234&#39;,
<a name="line330"></a>               fieldObj.getRange().getText());
<a name="line331"></a>}
<a name="line332"></a>
<a name="line333"></a>
<a name="line334"></a>/**
<a name="line335"></a> * Setup a real editable field (instead of a mock) and register the plugin to
<a name="line336"></a> * it.
<a name="line337"></a> */
<a name="line338"></a>function setUpRealEditableField() {
<a name="line339"></a>  fieldElem = document.createElement(&#39;div&#39;);
<a name="line340"></a>  fieldElem.id = &#39;myField&#39;;
<a name="line341"></a>  document.body.appendChild(fieldElem);
<a name="line342"></a>  fieldObj = new goog.editor.Field(&#39;myField&#39;, document);
<a name="line343"></a>  fieldObj.makeEditable();
<a name="line344"></a>  // Register the plugin to that field.
<a name="line345"></a>  plugin.getTrogClassId = goog.functions.constant(&#39;myClassId&#39;);
<a name="line346"></a>  fieldObj.registerPlugin(plugin);
<a name="line347"></a>}
<a name="line348"></a>
<a name="line349"></a>
<a name="line350"></a>/**
<a name="line351"></a> * Tear down the real editable field.
<a name="line352"></a> */
<a name="line353"></a>function tearDownRealEditableField() {
<a name="line354"></a>  if (fieldObj) {
<a name="line355"></a>    fieldObj.makeUneditable();
<a name="line356"></a>    fieldObj.dispose();
<a name="line357"></a>    fieldObj = null;
<a name="line358"></a>  }
<a name="line359"></a>  if (fieldElem &amp;&amp; fieldElem.parentNode == document.body) {
<a name="line360"></a>    document.body.removeChild(fieldElem);
<a name="line361"></a>  }
<a name="line362"></a>}
<a name="line363"></a>
<a name="line364"></a>
<a name="line365"></a>/**
<a name="line366"></a> * Tests that after the dialog is hidden via a keystroke, the editable field
<a name="line367"></a> * doesn&#39;t fire an extra SELECTIONCHANGE event due to the keyup from that
<a name="line368"></a> * keystroke.
<a name="line369"></a> * There is also a robot test in dialog_robot.html to test debouncing the
<a name="line370"></a> * SELECTIONCHANGE event when the dialog closes.
<a name="line371"></a> */
<a name="line372"></a>function testDebounceSelectionChange() {
<a name="line373"></a>  mockClock = new goog.testing.MockClock(true);
<a name="line374"></a>  // Initial time is 0 which evaluates to false in debouncing implementation.
<a name="line375"></a>  mockClock.tick(1);
<a name="line376"></a>
<a name="line377"></a>  setUpRealEditableField();
<a name="line378"></a>
<a name="line379"></a>  // Set up a mock event handler to make sure selection change isn&#39;t fired
<a name="line380"></a>  // more than once on close and a second time on close.
<a name="line381"></a>  var count = 0;
<a name="line382"></a>  fieldObj.addEventListener(goog.editor.Field.EventType.SELECTIONCHANGE,
<a name="line383"></a>                            function(e) {
<a name="line384"></a>                              count++;
<a name="line385"></a>                            });
<a name="line386"></a>
<a name="line387"></a>  assertEquals(0, count);
<a name="line388"></a>  plugin.execCommand(COMMAND);
<a name="line389"></a>  assertEquals(1, count);
<a name="line390"></a>  plugin.getDialog().hide();
<a name="line391"></a>  assertEquals(2, count);
<a name="line392"></a>
<a name="line393"></a>  // Fake the keyup event firing on the field after the dialog closes.
<a name="line394"></a>  var e = new goog.events.Event(&#39;keyup&#39;, plugin.fieldObject.getElement());
<a name="line395"></a>  e.keyCode = 13;
<a name="line396"></a>  goog.testing.events.fireBrowserEvent(e);
<a name="line397"></a>
<a name="line398"></a>  // Tick the mock clock so that selection change tries to fire.
<a name="line399"></a>  mockClock.tick(goog.editor.Field.SELECTION_CHANGE_FREQUENCY_ + 1);
<a name="line400"></a>
<a name="line401"></a>  // Ensure the handler did not fire again.
<a name="line402"></a>  assertEquals(2, count);
<a name="line403"></a>}
</pre>


</body>
</html>
